from openlabyrinth.models import Labyrinth, Node, Link, Counter, LinkVariance, Asset, Alert, RemoteStateObserver
from django.contrib import admin

class RemoteStateObserverInline(admin.TabularInline):
    model = RemoteStateObserver

class IncomingLinkInline(admin.TabularInline):
    model = Link
    verbose_name = 'Incoming Link'
    verbose_name_plural = 'Incoming Links'
    fk_name = 'destination'
    extra = 1

class OutgoingLinkInline(admin.TabularInline):
    model = Link
    verbose_name = 'Outgoing Link'
    verbose_name_plural = 'Outgoing Links'
    fk_name = 'source'
    extra = 3

class AlertInline(admin.TabularInline):
    model = Alert
    extra = 1

class NodeInline(admin.TabularInline):
    model = Node

class NodeAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {
            'fields': ['title', 'labyrinth', 'message', 'supporting_information']
        }),
        ('Navigational Options', {
            'fields': ['random_outbound_link', 'undo']
        }),
    ]
    list_display = ('title', 'labyrinth', 'random_outbound_link', 'undo')
    list_filter = ['labyrinth']
    search_fields = ['title']
    inlines = [OutgoingLinkInline, IncomingLinkInline]

class CounterInline(admin.TabularInline):
    model = Counter
    extra = 1

class CounterAdmin(admin.ModelAdmin):
    list_display = ('name', 'labyrinth', 'start_value', 'unit')
    list_filter = ['labyrinth']
    search_fields = ['name']
    inlines = [AlertInline]

class LabyrinthAdmin(admin.ModelAdmin):
    fields = ['name', 'keywords', 'authors', 'credits', 'time_limit', 'type', 'root_node', 'access', 'password', 'section_browsing']
    list_display = ('name', 'access')
    search_fields = ['name']
    inlines = [RemoteStateObserverInline]

admin.site.register(Node, NodeAdmin)
admin.site.register(Counter, CounterAdmin)
admin.site.register(Asset)
admin.site.register(Labyrinth, LabyrinthAdmin)
admin.site.register(LinkVariance)
